﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;



namespace Parser
{
    public class BaseParser:IDisposable
    {
        #region Auto properties

        protected string Login { get; set; }
        protected string Password { get; set; }
        protected string NetworkPath { get; set; }
        public string StorePath { get; set; }
        protected string[] Excepts { get; set; }

        #endregion

        #region Properties

        public NetworkPerson[] Persons
        {
            get
            {
                if (_persons == null)
                    return new NetworkPerson[0];
                return _persons.ToArray();
            }
        }

        #endregion

        #region Fields

        private IEnumerable<NetworkPerson> _persons;

        #endregion

        #region Methods

        [STAThread] 
        public virtual void StartParse()
        {
            if (!LoginIn())
                return;
            Excepts = NetworkPerson.GetNames(StorePath);
            GoToFirstMember();
            var m = GetDataFromMember();
            m.SavePersonToList(StorePath);
            while (GoToNextMember())
            {
                m = GetDataFromMember();
                m.SavePersonToList(StorePath);
            }
            Logout();
        }
        public void Dispose()
        {
            _persons = null;
        }

        #endregion

        #region Virtuals members

        protected virtual bool LoginIn()
        {
            throw new NotImplementedException();
        }
        protected virtual void GoToFirstMember(int first=1)
        {
            throw new NotImplementedException();
        }
        protected virtual bool GoToNextMember()
        {
            throw new NotImplementedException();
        }
        protected virtual NetworkPerson GetDataFromMember()
        {
            throw new NotImplementedException();
        }
        protected virtual void Logout()
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
